//
//  ServiceDetailView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/27.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "ServiceDetailView.h"

@interface ServiceDetailView()
@property(nonatomic,strong)UIView*registrationView;
@property(nonatomic,strong)UIView*confirmView;
@property(nonatomic,strong)UILabel*registration;
@property(nonatomic,strong)UILabel*confirm;
@property(nonatomic,strong)UILabel*source;
@property(nonatomic,strong)UILabel*Date;
@property(nonatomic,strong)UILabel*sourceLabel;
@property(nonatomic,strong)UILabel*totalMoney;
@property(nonatomic,strong)UILabel*StatusLabel;
@property(nonatomic,strong)UILabel*confirmSource;
@property(nonatomic,strong)UILabel*confirmDate;
@property(nonatomic,strong)UILabel*confirmSourceLabel;
@property(nonatomic,strong)UILabel*confirmTotalMoney;
@property(nonatomic,strong)UILabel*confirmStatusLabel;

@end
@implementation ServiceDetailView
{
    NSMutableArray*payment;
    
    NSString*payType;
    UIButton*zhangkai;
    UIButton*zhangkai1;
    NSString*serviceStatus;
    UILabel*registratInstructions;
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
    }
    return self;
}
#pragma mark InitUI
- (void)initUI
{
    self .backgroundColor = [UIColor whiteColor];
    
    
      }

-(void)setModel:(ServiceDetailModel *)model{
    [self initUI];
    [self setViewAutoLayout];
    serviceStatus=[[model.dict objectForKey:@"service"] objectForKey:@"serviceStatus"];
    _registrationView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 90)];
    _registrationView.backgroundColor=[UIColor whiteColor];
    [self addSubview:_registrationView];
    
    _registration=[[UILabel alloc]initWithFrame:CGRectMake(15, 15, ScreenWidth, 15)];
    _registration.textColor=shenhuiColor;
    _registration.text=@"登记信息";
    _registration.font=[UIFont systemFontOfSize:15];
    [self addSubview:_registration];

    _source=[[UILabel alloc]initWithFrame:CGRectMake(15, _registration.bottom+13, ScreenWidth, 14)];
    _source.textColor=shenhuiColor;
    _source.font=[UIFont systemFontOfSize:14];
    NSRange range1={0,10};
    NSString* string1 =[[[model.dict objectForKey:@"predict"] objectForKey:@"predictDate"] substringWithRange:range1];
    _source.text=[NSString stringWithFormat:@"来源 %@   %@",   [[model.dict objectForKey:@"predict"] objectForKey:@"predictName"],   string1];
    [self addSubview:_source];
    
    NSNumber*Total = [[model.dict objectForKey:@"predict"] objectForKey:@"predictMoney"];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
    NSString *s =[NSString stringWithFormat:@"收费金额 ¥%@",   formattedNumberString];
    UIFont *font = [UIFont systemFontOfSize:14];
    CGSize size = CGSizeMake(ScreenWidth-60, 2000);
    CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
    _totalMoney=[[UILabel alloc]initWithFrame:CGRectMake(15, _source.bottom+7, labelsize.width+5, 14)];
    _totalMoney.textColor=shenhuiColor;
    _totalMoney.text=[NSString stringWithFormat:@"收费金额 ¥%@",   formattedNumberString];
    _totalMoney.font=[UIFont systemFontOfSize:14];
     [self addSubview:_totalMoney];
    
    _StatusLabel=[[UILabel alloc]initWithFrame:CGRectMake(_totalMoney.right, _source.bottom+7, ScreenWidth, 14)];
    _StatusLabel.textColor=shenhuiColor;
    _StatusLabel.font=[UIFont systemFontOfSize:14];
 if ([[[model.dict objectForKey:@"service"] objectForKey:@"payStatus"]isEqualToString:@"N"]) {
        _StatusLabel.text=@"未支付";
        _StatusLabel.textColor=hongseColor;
    }else {
        _StatusLabel.text=@"已支付";
        _StatusLabel.textColor=luseColor;
    }
    [self addSubview:_StatusLabel];
    zhangkai=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-97, _source.bottom+7, 80, 12)];
    [zhangkai setTitle:@"展开更多" forState:UIControlStateNormal];
    [zhangkai setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    [zhangkai addTarget:self action:@selector(zhankai:) forControlEvents:UIControlEventTouchUpInside];
    zhangkai.titleLabel.font=[UIFont systemFontOfSize:12];
    zhangkai.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [self addSubview:zhangkai];
    
    UILabel*instructions=[[UILabel alloc]initWithFrame:CGRectMake(15,90+15, ScreenWidth*70/750, 15)];
    instructions.text=@"说明";
    instructions.font= [UIFont systemFontOfSize:15];
    [instructions setTextColor:shenhuiColor];
    [self addSubview:instructions];
    if ([[NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"predict"] objectForKey:@"predictDesc"]] length]>1) {
        NSString *s1 =[NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"predict"] objectForKey:@"predictDesc"]]];
        UIFont *font1 = [UIFont systemFontOfSize:14];
        CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        registratInstructions=[[UILabel alloc]initWithFrame:CGRectMake(15, instructions.bottom+12, ScreenWidth-40, labelsize1.height+30)];
        registratInstructions.text=s1;
        registratInstructions.numberOfLines=0;
        registratInstructions.font= [UIFont systemFontOfSize:14];
        [registratInstructions setTextColor:shenhuiColor];
        [self addSubview:registratInstructions];
    }else{
         registratInstructions=[[UILabel alloc]initWithFrame:CGRectMake(15, instructions.bottom+12, ScreenWidth-40, 30)];
        [self addSubview:registratInstructions];
    }
   
    
    
    
if ([[[model.dict objectForKey:@"service"] objectForKey:@"serviceStatus"] isEqualToString:@"C"]) {
        _confirmView=[[UIView alloc]initWithFrame:CGRectMake(0, _registrationView.bottom, ScreenWidth, 100)];
        _confirmView.backgroundColor=[UIColor whiteColor];
        [self addSubview:_confirmView];
    
        UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        view1.backgroundColor=zuiqianhuiColor;
        view1.layer.borderColor = qianhuiColor.CGColor;
        [view1.layer setBorderWidth:0.35];   //边
        [_confirmView addSubview:view1];
        
        
        _confirm=[[UILabel alloc]initWithFrame:CGRectMake(15, 15+10, 80, 15)];
        _confirm.text=@"确认信息";
        _confirm.textColor=shenhuiColor;
        _confirm.font=[UIFont systemFontOfSize:15];
        [_confirmView addSubview:_confirm];
        NSString* string1 =[[[model.dict objectForKey:@"confirm"] objectForKey:@"confirmDate"] substringWithRange:range1];
    
        _confirmSourceLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, _confirm.bottom+13, 250, 14)];
        _confirmSourceLabel.text=[NSString stringWithFormat:@"来源 %@ %@",   [[model.dict objectForKey:@"confirm"] objectForKey:@"confirmName"],   string1];
        _confirmSourceLabel.textColor=shenhuiColor;
        _confirmSourceLabel.font=[UIFont systemFontOfSize:14];
        [_confirmView addSubview:_confirmSourceLabel];
        
        NSNumber*Total1 = [[model.dict objectForKey:@"confirm"] objectForKey:@"confirmMoney"];
        
        NSNumberFormatter *numberFormatter1 = [[NSNumberFormatter alloc] init];
        [numberFormatter1 setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString1 = [numberFormatter1 stringFromNumber:[NSNumber numberWithDouble:Total1.doubleValue]];
        
        NSString *ss1 =[NSString stringWithFormat:@"收费金额 ¥ %@",   formattedNumberString1];
        
        UIFont *font1ss1 = [UIFont systemFontOfSize:contenfot];
        CGSize size1ss1 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize1ss1 = [ss1 sizeWithFont:font1ss1 constrainedToSize:size1ss1 lineBreakMode:NSLineBreakByCharWrapping];
        
        _confirmTotalMoney=[[UILabel alloc]initWithFrame:CGRectMake(15, _confirmSourceLabel.bottom+7, labelsize1ss1.width+10, 14)];
        _confirmTotalMoney.text=[NSString stringWithFormat:@"收费金额 ¥ %@",   formattedNumberString1];
        _confirmTotalMoney.textColor=shenhuiColor;
        _confirmTotalMoney.font=[UIFont systemFontOfSize:14];
        [_confirmView addSubview:_confirmTotalMoney];
        
       _confirmSource=[[UILabel alloc]initWithFrame:CGRectMake(_confirmTotalMoney.right, _confirmSourceLabel.bottom+7, 160, 14)];
        if ([[[model.dict objectForKey:@"service"] objectForKey:@"payStatus"]isEqualToString:@"N"]) {
            _confirmSource.text=@"未支付";
            _confirmSource.textColor=hongseColor;
        }else {
            _confirmSource.text=@"已支付";
            _confirmSource.textColor=luseColor;
            
            
        }
        _confirmSource.font=[UIFont systemFontOfSize:14];
        [_confirmView addSubview:_confirmSource];
        
        
        zhangkai1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-97, _confirmSourceLabel.bottom+7, 80, 12)];
        [zhangkai1 setTitle:@"展开更多" forState:UIControlStateNormal];
        [zhangkai1 setTitleColor:zhonghuiColor forState:UIControlStateNormal];
        [zhangkai1 addTarget:self action:@selector(zhankai1:) forControlEvents:UIControlEventTouchUpInside];
        zhangkai1.titleLabel.font=[UIFont systemFontOfSize:12];
        zhangkai1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
        [_confirmView addSubview:zhangkai1];
    
        UILabel*instructions1=[[UILabel alloc]initWithFrame:CGRectMake(15,95+15, ScreenWidth*70/750, 15)];
        instructions1.text=@"说明";
        instructions1.font= [UIFont systemFontOfSize:15];
        [instructions1 setTextColor:shenhuiColor];
        [_confirmView addSubview:instructions1];
        
        if ([[NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"confirm"] objectForKey:@"confirmDesc"]] length]>1) {
            
            
            NSString *s1 =[NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"confirm"] objectForKey:@"confirmDesc"]]];
            UIFont *font1 = [UIFont systemFontOfSize:contenfot];
            CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
            CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
            
            UILabel*confirmInstructions=[[UILabel alloc]initWithFrame:CGRectMake(15, instructions1.bottom+12, ScreenWidth-40, labelsize1.height+30)];
            confirmInstructions.text=s1;
            confirmInstructions.numberOfLines=0;
            confirmInstructions.font= [UIFont systemFontOfSize:contenfot];
            [confirmInstructions setTextColor:shenhuiColor];
            [_confirmView addSubview:confirmInstructions];
        }else{
             UILabel*confirmInstructions=[[UILabel alloc]initWithFrame:CGRectMake(15, instructions1.bottom+12, ScreenWidth-40, 30)];
            [_confirmView addSubview:confirmInstructions];
            
        }
        
        _confirmMoneyVIew=[[UIView alloc]initWithFrame:CGRectMake(0, _confirmView.bottom, ScreenWidth, 200)];
        _confirmMoneyVIew.backgroundColor=zuiqianhuiColor;
        [self addSubview:_confirmMoneyVIew];
        [self confirmMoney:[[model.dict objectForKey:@"confirm"] objectForKey:@"confirmMoney"]];
    }else{
        _confirmMoneyVIew=[[UIView alloc]initWithFrame:CGRectMake(0, _registrationView.bottom, ScreenWidth, 200)];
        _confirmMoneyVIew.backgroundColor=zuiqianhuiColor;
        [self addSubview:_confirmMoneyVIew];
        [self confirmMoney:[[model.dict objectForKey:@"confirm"] objectForKey:@"confirmMoney"]];
    }
}

-(void)zhankai:(UIButton*)sender
{
    [zhangkai removeFromSuperview];
    [zhangkai1 removeFromSuperview];
    _registrationView.frame=CGRectMake(0,0, ScreenWidth, registratInstructions.bottom);
    if ([serviceStatus isEqualToString:@"C"]) {
        _confirmView.frame=CGRectMake(0, _registrationView.bottom+10, ScreenWidth, 180);
        _confirmMoneyVIew.frame=CGRectMake(0, _confirmView.bottom, ScreenWidth, 200);
    }else{
        _confirmMoneyVIew.frame=CGRectMake(0, _registrationView.bottom, ScreenWidth, 200);
    }
    
}
-(void)zhankai1:(UIButton*)sender
{
    [zhangkai1 removeFromSuperview];

    _confirmView.frame=CGRectMake(0, _registrationView.bottom+10, ScreenWidth, 180);
    _confirmMoneyVIew.frame=CGRectMake(0, _confirmView.bottom, ScreenWidth, 200);
    
}
-(void)setViewAutoLayout
{
    
    
}
-(void)confirmMoney:(NSString*)str{


   
    NSNumberFormatter *numberFormatte = [[NSNumberFormatter alloc] init];
    [numberFormatte setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString5 = [numberFormatte stringFromNumber:[NSNumber numberWithDouble:str.doubleValue]];
    
    UILabel*jine=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-200, 30, 183, 45)];
    jine.text=[NSString stringWithFormat:@"服务金额 ¥ %@",   formattedNumberString5];
    jine.textColor=[UIColor blackColor];
    jine.font=[UIFont systemFontOfSize:24];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"服务金额 ¥ %@",   formattedNumberString5]];
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:15.0]
     
                          range:NSMakeRange(0, 6)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:shenhuiColor
     
                          range:NSMakeRange(0,6)];
    
    
    jine.attributedText = AttributedStr;
    jine.textAlignment=NSTextAlignmentRight;
    [_confirmMoneyVIew addSubview:jine];
    
    

}
@end
